package com.svm.util;

import java.io.File;

public class FileUtils {

	public static void cleanTmpDir() {

		File file = new File(SystemConfig.TMP_REPOSITORY);

		for (File f : file.listFiles()) {
			f.delete();
		}
	}

	public static void deleteFiles() {

		File file;

		file = new File(SystemConfig.CLASS_FILES_REPOSITORY);
		for (File f : file.listFiles()) {
			f.delete();
		}

		file = new File(SystemConfig.FEATURES_IMAGE_REPOSITORY);
		for (File f : file.listFiles()) {
			if (f.isDirectory()) {
				for (File f2 : f.listFiles()) {
					f2.delete();
				}
			}
			f.delete();
		}

		file = new File(SystemConfig.SVM_FILES_REPOSITORY);
		for (File f : file.listFiles()) {
			f.delete();
		}

		file = new File(SystemConfig.XML_REPOSITOTY);
		for (File f : file.listFiles()) {
			f.delete();
		}

	}

	public static void configEnvironment() {

		File file = new File(SystemConfig.REPOSITORY);

		if (!file.isDirectory()) {
			file.mkdir();

			file = new File(SystemConfig.CLASS_FILES_REPOSITORY);

			if (!file.isDirectory()) {
				file.mkdir();
			}

			file = new File(SystemConfig.FEATURES_IMAGE_REPOSITORY);

			if (!file.isDirectory()) {
				file.mkdir();
			}

			file = new File(SystemConfig.SVM_FILES_REPOSITORY);

			if (!file.isDirectory()) {
				file.mkdir();
			}

			file = new File(SystemConfig.TMP_REPOSITORY);

			if (!file.isDirectory()) {
				file.mkdir();
			}

			file = new File(SystemConfig.XML_REPOSITOTY);

			if (!file.isDirectory()) {
				file.mkdir();
			}

		}

	}

}
